package com.glut.campusrepair.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glut.campusrepair.entity.RepairPersonnel;
import com.glut.campusrepair.mapper.RepairPersonnelMapper;
import com.glut.campusrepair.service.IRepairPersonnelService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 维修人员表 服务实现类
 *
 * @author sanminzhi
 * @since 2024-07-19 11:26
 */
@Service
public class RepairPersonnelServiceImpl extends ServiceImpl<RepairPersonnelMapper, RepairPersonnel> implements IRepairPersonnelService {
    //    @Override
//    public IPage page1(IPage<RepairPersonnel> page) {
//        return repairPersonnelMapper.page1(page);
//    }
    @Resource
    private RepairPersonnelMapper repairPersonnelMapper;


    @Override
    public IPage page2(Page<RepairPersonnel> page, Wrapper wrapper) {
        return repairPersonnelMapper.page2(page,wrapper) ;
    }

    @Override
    public Integer getRepairPersonnelId(String username) {
        QueryWrapper<RepairPersonnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        RepairPersonnel repairPersonnel = getOne(queryWrapper);

        if (repairPersonnel == null) {
            // 可以抛出自定义异常、返回默认值或日志记录等
            return null; // 或者 throw new MyException("Repair personnel not found");
        }

        return repairPersonnel.getRepairPersonnelId();
    }
}
